package com.xiao.admin.controller;

import java.util.Arrays;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.xiao.admin.entity.UsersEntity;
import com.xiao.admin.service.UsersService;
import com.xiao.group.common.utils.PageUtils;
import com.xiao.group.common.utils.R;



/**
 * 
 *
 * @author 韩国涛
 * @email 2845009006@gmail.com
 * @date 2021-09-12 08:56:29
 */
@RestController
@RequestMapping("admin/users")
public class UsersController {
    @Autowired
    private UsersService usersService;

    @RequestMapping("tologin")
    public R tologin(@RequestBody UsersEntity usersEntity){
        return usersService.tologin(usersEntity);
    }

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = usersService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info")
    public UsersEntity info(@RequestParam(value = "id",defaultValue = "0") Integer id){
		UsersEntity users = usersService.getById(id);

        return users;
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody UsersEntity users){
        boolean save = usersService.save(users);
        return R.ok().put("data",save);
    }
    @RequestMapping("/toblur")
    public UsersEntity toblur(@RequestParam(value = "username",defaultValue = "")String username){
        return usersService.tonlur(username);
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody UsersEntity users){
		usersService.updateById(users);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Integer[] ids){
		usersService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
